package com.fauks.ssm.spring;

import com.fauks.ssm.mybatis.bean.Person;
import com.fauks.ssm.spring.tx_annotation.IBookService;
import com.fauks.ssm.spring.tx_annotation.TxService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class _03TestTx {

    private ApplicationContext ac;

    @Before
    public void createBeanFactory() {
        //1.创建Ioc容器对象
        ac = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-tx-annotation.xml");
    }

    //测试更新操作
    @Test
    public void testTxByAnnotation() {
        IBookService bookService = ac.getBean("bookServiceImpl", IBookService.class);
        bookService.buyBook("fauks", 1);
    }

    @Test
    public void testTx() {
        TxService txService = ac.getBean("txService", TxService.class);
        Person person = new Person();
        person.setId(1);
        person.setName("fasdfasdf");
        txService.update(person);
    }
}
